//    Copyright (C) Clear Office.  All rights reserved.
using System;
using Office.Core.Serialization;

namespace Office.Spreadsheet.PivotTable
{
    class Item: IOfficeXmlSerializable
    {
        private string _n;
        private ItemType _t;
        private bool _h;
        private bool _s;
        private bool _sd = true;
        private bool _f;
        private bool _m;
        private uint? _x;
        private bool _d;
        private bool _e;
        private bool _c;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("item"))
            {
                _n = c.GetOptionalString("n");
                _t = c.GetOptionalEnum("t", ItemType.Data);
                _h = c.GetOptionalBoolean("h", false);
                _s = c.GetOptionalBoolean("s", false);
                _sd = c.GetOptionalBoolean("sd", true);
                _f = c.GetOptionalBoolean("f", false);
                _m = c.GetOptionalBoolean("m", false);
                _c = c.GetOptionalBoolean("c", false);
                _x = c.GetOptionalUInteger("x");
                _d = c.GetOptionalBoolean("d", false);
                _e = c.GetOptionalBoolean("e", true);
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("item"))
            {
                c.SetOptionalString("n", _n);
                c.SetOptionalEnum("t", _t, ItemType.Data);
                c.SetOptionalBoolean("h", _h, false);
                c.SetOptionalBoolean("s", _s, false);
                c.SetOptionalBoolean("sd", _sd, true);
                c.SetOptionalBoolean("f", _f, false);
                c.SetOptionalBoolean("m", _m, false);
                c.SetOptionalBoolean("c", _c, false); //\\
                c.SetOptionalUInteger("x", _x); //\\
                c.SetOptionalBoolean("d", _d, false);
                c.SetOptionalBoolean("e", _e, true);
            }
        }
    }
}